var url = '/kobe/account/findPage';
// var currentPage=1;
// var count=2;
$(function () {
    var currentPage=1;
    var count=2;
    $.get(url, showResult);
    $('#datalist').submit(function (e) {
        e.preventDefault();
        //把表单数据转化为:page=1&count=2 的形式
        var arr=$(this).serializeArray();
       currentPage=Number(arr[0].value);
       count= Number(arr[1].value);
        $.get('../account/findPage', $(this).serialize(), showResult);
    });

    $('#prev').click(function () {
        if(currentPage<=0){
            currentPage=1;
        }
        if(count<=0){
            count=2;
        }
        var params={
            page:--currentPage,
            count:count
        };
        $.get(url, params, showResult);

    });
    $('#next').click(function () {
        // currentPage++;
        if(count<=0){
            count=2;
        }
        if(currentPage<=0){
            currentPage=1;
        }
        var params={
            page:++currentPage,
            count:count
        };
        $.get(url, params, showResult);

    });

    $('#firstPage').click(function () {
        if(count<=0){
            count=2;
        }
        if(currentPage<=0){
            currentPage=1;
        }
        var params={
            page:1,
            count:2
        };
        $.get('../account/findPage', params, showResult);


    });
    $('#endPage').click(function (resp) {
        var totalCount = resp.data.totalCount;
        var pages = Math.ceil(totalCount / rowCount);
        var params={
            page:pages,
            count:2
        };

        $.get('../account/findPage', params, showResult);


    })
});
function showResult(resp) {
    console.log(resp.status);
    if (resp.status === 200) {
        //取到总条数,和请求的数据
        var totalCount = resp.data.totalCount;
        var items = resp.data.items;
        var tbody = $('#tbody');
        tbody.empty();
        for (var item of items) {
            var tr = $('<tr></tr>');
            var accountId = $('<td></td>').text(item.accountId);
            var realName = $('<td></td>').text(item.realName);
            var idCard = $('<td></td>').text(item.idcardNo);
            var loginName = $('<td></td>').text(item.loginName);
            var status = $('<td></td>').text(item.status);
            var createDate = $('<td></td>').text(item.createDate);
            var lastLoginTime = $('<td></td>').text(item.lastLoginTime);
            var td = $('<td></td>');
            var stput = $('<input type="button" value="暂停" class="btn_pause" onclick="setState();" />');
            var startput = $('<input type="button" value="开通" class="btn_start" onclick="setState();" />');
            var modput = $('<input type="button" value="修改" class="btn_modify" />');
            var delput = $('<input type="button" value="删除" class="btn_delete" onclick="deleteAccount();"/>');
            if (item.status === "0") {
                td.append(stput)
            }
            if (item.status === "1") {
                td.append(startput)
            }
            td.append(modput).append(delput);
            tr.append(accountId).append(realName).append(idCard).append(loginName).append(status).append(createDate).append(lastLoginTime).append(td);
            tbody.append(tr);
        }
    }

}